package dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import orm.CollectivityTeachingPlan;
import orm.CollectivityWeekArrange;
import orm.TeachingPlanBaseInfo;
import util.DBHelper;

public class CollectivityTeachingPlanDAO {
	
	
	public void insertCTP(Statement statement, CollectivityTeachingPlan ctp) throws SQLException {
		statement.execute("insert into collectivityteachingplan values('" + ctp.getTpID() + "'," +
				ctp.getAppropriateClass() + ", " + ctp.getDevelopmentDomain() +
				", '" + ctp.getUsageMaterial() + "', '" + ctp.getActivityPurpose() + "', '" + 
				ctp.getActivityPreparation() + "', '" + ctp.getTeachingContent() + "', " + ctp.getTeachingWay() +
				", '" + ctp.getActivityTime() + "', " + ctp.getChildrenNum() + ", '" + ctp.getChildrenAge() + "', " +
				ctp.getTeachersNum() + ", '" + ctp.getMajorTeacherAssignment() + "', '" + 
				ctp.getAssistantTeacherAssignment() + "', '" + ctp.getExistentKnowledge() + "', '" +
				ctp.getActivityStepReporting() + "', '" + ctp.getTeachingMaterial() + "', '" +
				ctp.getTeachingExperience() + "')");
	}
	
	public void updateCTP(Statement statement, CollectivityTeachingPlan ctp) throws SQLException {
		statement.execute("update collectivityteachingplan set AppropriateClass = " +
				ctp.getAppropriateClass() + ", DevelopmentDomain = " + ctp.getDevelopmentDomain() + ", UsageMaterial = '" + 
				ctp.getUsageMaterial() + "', ActivityPurpose = '" + ctp.getActivityPurpose() + 
				"', ActivityPreparation = '" +  ctp.getActivityPreparation() + "', TeachingContent = '" + 
				ctp.getTeachingContent() + "', TeachingWay = " + ctp.getTeachingWay() + 
				", ActivityTime = '" + ctp.getActivityTime() + "', ChildrenNum = " + ctp.getChildrenNum() + 
				", ChildrenAge = '" + ctp.getChildrenAge() + "', TeachersNum = " + ctp.getTeachersNum() + 
				", MajorTeacherAssignment = '" + ctp.getMajorTeacherAssignment() + "', AssistantTeacherAssignment ='" + 
				ctp.getAssistantTeacherAssignment() + "', ExistentKnowledge = '" + ctp.getExistentKnowledge() + 
				"', ActivityStepReporting = '" + ctp.getActivityStepReporting() + "', TeachingMaterial = '" + 
				ctp.getTeachingMaterial() + "', TeachingExperience ='" + ctp.getTeachingExperience() + 
				"' where TPID = '" + ctp.getTpID() + "'");
	}
	
	public void deleteCTP(Statement statement, String tpid) throws SQLException {
		statement.execute("delete from collectivityteachingplan where TPID='" + tpid + "'");
	}
	
	public CollectivityTeachingPlan getCTPByTPID(String tpid) throws SQLException {
		Connection conn = null;
		Statement stmt = null;
		ResultSet rs = null;
		CollectivityTeachingPlan ctp = new CollectivityTeachingPlan();
		conn = DBHelper.getConnection();
		stmt = conn.createStatement();
		rs = stmt.executeQuery("select * from collectivityteachingplan where TPID='" + tpid + "'");
		
		while (rs.next()) {
			int i = 1;
			ctp.setTpID(rs.getString(i++));
			ctp.setAppropriateClass(rs.getInt(i++));
			ctp.setDevelopmentDomain(rs.getInt(i++));
			ctp.setUsageMaterial(rs.getString(i++));
			ctp.setActivityPurpose(rs.getString(i++));
			ctp.setActivityPreparation(rs.getString(i++));
			ctp.setTeachingContent(rs.getString(i++));
			ctp.setTeachingWay(rs.getInt(i++));
			ctp.setActivityTime(rs.getString(i++));
			ctp.setChildrenNum(rs.getInt(i++));
			ctp.setChildrenAge(rs.getString(i++));
			ctp.setTeachersNum(rs.getInt(i++));
			ctp.setMajorTeacherAssignment(rs.getString(i++));
			ctp.setAssistantTeacherAssignment(rs.getString(i++));
			ctp.setExistentKnowledge(rs.getString(i++));
			ctp.setActivityStepReporting(rs.getString(i++));
			ctp.setTeachingMaterial(rs.getString(i++));
			ctp.setTeachingExperience(rs.getString(i++));
		}
		
		rs.close();
		stmt.close();
		conn.close();
		
		return ctp;
	}
	
}
